package ua.kpi_java_training.zabrodskyi.module3;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * @author Maksym Zabrodskyi
 * @version 23-Jun-2013
 */
public class VictimTest {

	Victim victim;
	Cell cell;

	@Test
	public void shouldCreateVictim() {
		cell = new Cell(2, 4);
		victim = new Victim(cell);
		assertNotNull(victim);
	}

	@Test(expected = Exception.class)
	public void shouldExceptionCreateVictim() {
		cell = new Cell(-2, -4);
		victim = new Victim(cell);
	}

	@Test
	public void shouldMoveVictim() {
		Environment environment = new Environment(Settings.getWidth(),
				Settings.getHeight());
		environment.add(ElementType.VICTIM);
		victim = (Victim) environment.getElement(0);
		cell = victim.getCell();
		victim.move(environment);
		Cell newCell = victim.getCell();
		assertFalse(cell.equals(newCell));
	}

	@Test
	public void shouldSpawnNewVictim() {
		Environment environment = new Environment(Settings.getWidth(),
				Settings.getHeight());
		environment.add(ElementType.VICTIM);
		victim = (Victim) environment.getElement(0);
		for (int countOfMovements = 0; countOfMovements < 20; countOfMovements++) {
			victim.move(environment);
			victim.spawn(environment);
		}
		int actualCountVictims = environment
				.getCountElements(ElementType.VICTIM);
		assertEquals(3, actualCountVictims);
	}

	@Test
	public void shouldGetCellInWitchVictimIsIt() {
		cell = new Cell(2, 4);
		victim = new Victim(cell);
		Cell newCell = victim.getCell();
		assertTrue(cell.equals(newCell));
	}

	@Test
	public void shouldSetNewCellForVictim() {
		cell = new Cell(2, 5);
		victim = new Victim(cell);
		Cell newCell = new Cell(1, 1);
		victim.setCell(newCell);
		cell = victim.getCell();
		assertTrue(cell.equals(newCell));
	}

	@Test(expected = Exception.class)
	public void shouldExceptionSetNewCellForVictim() {
		cell = new Cell(2, 4);
		victim = new Victim(cell);
		Cell newCell = new Cell(-1, -2);
		victim.setCell(newCell);
	}

	@Test
	public void shouldGetTypeVictim() {
		cell = new Cell(4, 5);
		victim = new Victim(cell);
		ElementType actualType = victim.getType();
		assertEquals(ElementType.VICTIM, actualType);
	}

	@Test
	public void testToString() {
		cell = new Cell(2, 3);
		victim = new Victim(cell);
		String expected = "VICTIM is on cell [2,3]";
		assertEquals(expected, victim.toString());
	}

}
